<script >
export default {
    data(){
      return{
        jigoudata:[],
        form:{
          jigouname:'',
          chepainame:''
        },
          errorMessage:''
      }
  },
  methods:{
    findAll(){
      this.axios.get("http://1.94.221.254:7072/jigou/findAll").then(res=>{
        this.jigoudata=res.data
        console.log(res.data)
      })
    },
    onSubmit(){
      const licensePlateReg = /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[ABCDEFGHJKLMNPQRSTUVWXYZ0-9])|([ABCDEFGHJKLMNPQRSTUVWXYZ0-9]{4}[0-9ABCDEFGHJKLMNPQRSTUVWXYZ])))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;
      if (this.form.chepainame!=''&&this.form.chepainame!=null&&licensePlateReg.test(this.form.chepainame)){
        this.$message.success("查询成功")
      }else{
        this.$message.error("车牌号不正确")
      }
    },
    onClickLeft(){
      this.$router.push('/shouye')
    },
    chazhao(){
      // 车牌号正则表达式，新能源车牌号格式：[省份简称（1 位汉字）+ 发牌机关代号（1 位字母）+ 序号（6 位）]，非新能源车牌号格式：[省份简称（1 位汉字）+ 地区代码（1 位字母）+ 5 位序号]
      const licensePlateReg = /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[ABCDEFGHJKLMNPQRSTUVWXYZ0-9])|([ABCDEFGHJKLMNPQRSTUVWXYZ0-9]{4}[0-9ABCDEFGHJKLMNPQRSTUVWXYZ])))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;
      if (licensePlateReg.test(this.form.chepainame)) {
        this.errorMessage = "车牌号正确";
      } else {
        this.errorMessage = "车牌号格式不正确";
      }
    }
  },
  created(){
    this.findAll();
    var token = localStorage.getItem('token');
    if (token === null) {
      this.$router.push('/');
    }
  },
}
</script>

<template>
  <div>

    <van-nav-bar
        title="年审"
        left-text="返回"

        left-arrow
        @click-left="onClickLeft"

    />
    <van-form @submit="onSubmit">
      代办机构:<van-dropdown-menu >
      <el-select v-model="form.jigouname" placeholder="请选择代办机构" >
        <el-option v-for="item in jigoudata" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
    </van-dropdown-menu>
      车牌号:<van-field v-model="form.chepainame" placeholder="请输入车牌号" @blur="chazhao" />{{errorMessage}}
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">查询</van-button>
      </div>
    </van-form>

  </div>
</template>

<style scoped>

</style>
